//
//  LGPatientDetailController2.m
//  HeartDisease_YHJK
//
//  Created by 1234 on 2025/9/22.
//  患者详情 -- 市一呼吸 -- 慢阻肺、哮喘

#import "LGPatientDetailController2.h"
//患者基本信息
#import "LGPatientBasicInfoController.h"
//电话随访
#import "LGMedicineBallPhoneController.h"
//团队咨询
#import "TUIGroupChatViewController.h"
#import "TUIChatConversationModel.h"

//报告详情
#import "LGSingleReportDetailController.h"

#import "LGPatientBreathePhotoController.h"

//添加就诊弹框
#import "LGPatientDetailAddNodeView.h"

//Header 、Cell
#import "LGPatientDetailHeaderView.h"
#import "LGPatientBreatheHeader.h"
#import "LGPatientBreatheTextCell.h"
#import "LGPatientBreatheReportCell.h"
#import "LGPatientDetailBreatheCell.h"

//底部按钮跳转
//复诊计划
#import "LGPatientCarePlanController.h"
//上传报告
#import "LGUploadIdentReportController.h"
//加入项目
#import "LGJoinProjectViewController.h"
//药物管理
#import "LGMedicineManageController.h"
//体征监测
#import "LGCancerMonitoringController.h"
//检验检查报告
#import "LGReportingCenterController.h"
//呼吸训练记录
#import "LGBreathRecordController.h"
//治疗记录
#import "LGCancerTreatRecordController.h"
//测评记录
#import "LGEvaluationReportController.h"
//开具医嘱
#import "LGAddDoctorAdviceController.h"
//添加随访
#import "LGMedicineBallFollowUpRecorder.h"
//聊天
#import "LGBubbleMessageCell.h"
#import "LGTextMessageCell.h"
#import "LGSystemMessageCell.h"
#import "LGVoiceMessageCell.h"
#import "LGImageMessageCell.h"
#import "LGFaceMessageCell.h"
#import "LGVideoMessageCell.h"

//自定义消息
//医生详情
#import "LGPersionalDataController.h"
//订单详情
#import "LGOrderDetailController.h"
//服务部详情
#import "LGServiceDetailController.h"
//随访记录
#import "LGFollowAdviceRecordController.h"
#import "LGPatientCardRecordCell.h"
#import "LGConsultStartEndCell2.h"
#import "LGCustomTextMessageCell2.h"
#import "LGConsultationAdviceCell2.h"
#import "LGRecommendDoctorCell2.h"
#import "LGRecommendServiceCell2.h"
#import "LGConsultEvaluationCell2.h"
#import "LGFollowUpRecommedCell2.h"
#import "LGCustomCellData.h"

//语音、视频、图片 - 播放、放大 工具
#import "LGMessageRecordManager.h"
#import "LGMessageMediaView.h" //图片查看大图
#import "TUIMediaCollectionCell.h"
#import "TUIMessageDataProvider.h"


@interface LGPatientDetailController2 ()<UITableViewDelegate,UITableViewDataSource,LGMessageRecordDelegate>
/**   */
@property (nonatomic , strong)TUIMessageDataProvider *messageDataProvider;

@property (nonatomic , strong)TUIBaseMessageController *messageController;
/**   */
@property (nonatomic , assign)LGMessageRecordManager *manager;
/**   */
@property (nonatomic , strong)LGPatientDetailHeaderView *headView;
/**   */
@property (nonatomic , strong)UITableView *tableView;
/**   */
@property (nonatomic , strong)UIView *tableHeaderView;
/**   */
@property (nonatomic , strong)UILabel *warnLabel;
/**  添加就诊 */
@property (nonatomic , strong)UIButton *addNodeBtn;
/**  底部-工作台 */
@property (nonatomic , strong)UIView *bottomView;
@property (nonatomic , strong)UIView *bottomItemView;
@property (nonatomic , strong)UIButton *openButton;
/**  上方按钮数组 */
@property (nonatomic , strong)NSArray *itemArray;
/**  下方列表数组 */
@property (nonatomic , strong)NSArray *dataArray;
/**  聊天消息 */
@property (nonatomic , strong)NSMutableDictionary *heightDic;
@property (nonatomic , strong)NSArray *systemArray;
@property (nonatomic , strong)NSArray *mediaArray;
/**   */
@property (nonatomic , strong)NSArray *photoArray;

/**  节点类型：1-基线 、 2-复诊复查 、 3-随访 、 4-咨询 、 5-住院 */
@property (nonatomic , copy)NSString *noteType;
/**   */
@property (nonatomic , copy)NSString *nodeid;
/**   */
@property (nonatomic , assign)NSInteger itemIndex;

@end

@implementation LGPatientDetailController2

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.nodeid = @"0";
    self.manager = [LGMessageRecordManager sharedManager];
    [self createSubView];
    self.systemArray = @[@"TIMCustom_01",@"TIMCustom_03",@"TIMCustom_05",@"TIMCustom_07",@"TIMCustom_12",@"TIMCustom_13",@"TIMCustom_15",@"TIMCustom_16",@"TIMCustom_18",@"TIMCustom_30",@"TIMCustom_31"];
    
    //自定义添加消息
    NSArray *cellArray = @[
                          //自定义添加消息
                          @{BussinessID : @"TIMCustom_01",//发起咨询
                            TMessageCell_Name : @"LGCustomTextMessageCell2",
                          },
                          @{BussinessID : @"TIMCustom_03",//咨询已开启
                            TMessageCell_Name : @"LGConsultStartEndCell2",
                          },
                          @{BussinessID : @"TIMCustom_05",//延长咨询时间
                            TMessageCell_Name : @"LGCustomTextMessageCell2",
                          },
                          @{BussinessID : @"TIMCustom_07",//咨询已结束
                            TMessageCell_Name : @"LGConsultStartEndCell2",
                          },
                          @{BussinessID : @"TIMCustom_12",//视频咨询-发起就诊提示
                            TMessageCell_Name : @"LGCustomTextMessageCell2",
                          },
                          @{BussinessID : @"TIMCustom_13",//问诊结束
                            TMessageCell_Name : @"LGConsultStartEndCell2",
                          },
                          @{BussinessID : @"TIMCustom_15",//视频通话
                            TMessageCell_Name : @"LGCustomTextMessageCell2",
                          },
                          @{BussinessID : @"TIMCustom_16",//视频通话
                            TMessageCell_Name : @"LGCustomTextMessageCell2",
                          },
                          @{BussinessID : @"TIMCustom_18",//咨询取消
                            TMessageCell_Name : @"LGConsultStartEndCell2",
                          },
                          @{BussinessID : @"TIMCustom_30",//候诊室
                            TMessageCell_Name : @"LGCustomTextMessageCell2",
                          },
                          @{BussinessID : @"TIMCustom_31",//候诊室
                            TMessageCell_Name : @"LGCustomTextMessageCell2",
                          }];
   
    //自定义消息
    for (NSDictionary *messageInfo in cellArray) {
        NSString *bussinessID = messageInfo[BussinessID];
        NSString *cellName = messageInfo[TMessageCell_Name];
        Class cls = NSClassFromString(cellName);
        if (cls && bussinessID) {
            [self.tableView registerClass:cls forCellReuseIdentifier:bussinessID];
        }
    }
    __weak typeof(self) weakSelf = self;
    self.headView.selectItemAtIndex = ^(NSInteger index) {
        weakSelf.itemIndex = index;
    };
    self.headView.editItemAtIndex = ^(NSInteger index) {
        if (index < weakSelf.itemArray.count) {
            NSDictionary *tempDic = weakSelf.itemArray[index];
            NSString *noteType = LGNSString(tempDic[@"node_type"]);
            if ([noteType isEqualToString:@"1"] || [noteType isEqualToString:@"2"]) {
                [weakSelf editNodeWithNodeid:LGNSString(tempDic[@"node_id"])];
            }else{
                [TooltipView showMessage:@"当前节点不可编辑" offset:0];
            }
        }
    };
    //查看医生详情
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkDoctorDetail:) name:@"CheckDoctorDetail2" object:nil];
    //视频咨询订单详情
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkVideoOrderDetail:) name:@"CheckOrderDetail2" object:nil];
    //慢病服务详情
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkServiceDetail:) name:@"CheckServiceDetail2" object:nil];
    //去做评估
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkEvaluationDetail:) name:@"CheckEvaluationDetail2" object:nil];
    //查看医嘱详情
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkDoctorAdviceDetail:) name:@"CheckDoctorAdviceDetail2" object:nil];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self requestData];
}

//请求节点数据
-(void)requestData{
    [RequestUtil withPOST:@"/doctor/patient.Patient/archive" parameters:@{@"patient_id":self.patientid,@"level_id":self.levelid} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        if (code == 200) {
            self.headView.dataDic = returnData;
            self.itemArray = returnData[@"timeline"];
        }
    } error:^(NSError *error) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        [self.emptyView showViewWithImage:@"emptyView2" content:@"请求失败" offset:0];
    }];
}

//请求节点下数据
-(void)requestNodeData:(NSDictionary *)dataDic{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [RequestUtil withPOST:@"/doctor/patient.Patient/nodeData" parameters:@{@"node_id":LGNSString(dataDic[@"node_id"]),@"node_type":LGNSString(dataDic[@"node_type"]),@"patient_id":LGNSString(dataDic[@"patient_id"]),@"level_id":LGNSString(self.levelid)} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if (code == 200) {
            NSString *warn = LGNSString(returnData[@"warn"]);
            self.warnLabel.text = warn;
            if ([warn isEmptyString]) {
                self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_W-viewPix(32), viewPix(10))];
            }else{
                self.tableView.tableHeaderView = self.tableHeaderView;
            }
            self.photoArray = returnData[@"imgs"];
            
            //数组数据
            NSArray *infoArray = returnData[@"structs"];
            if ([self.noteType isEqualToString:@"4"]) {
                //线上咨询
                self.tableView.cornerRidus = 0;
                self.tableView.backgroundColor = [UIColor colorWithString:@"#F2F3F5"];
                NSMutableArray *dataArray = [NSMutableArray array];
                NSMutableArray *mediaArray = [NSMutableArray array];
                NSInteger currentTime = 0;
                NSArray *tempArray = infoArray;
                for (NSInteger i=0; i<tempArray.count; i++) {
                    NSMutableDictionary *tempDic = [NSMutableDictionary dictionaryWithDictionary:tempArray[i]];
                    NSInteger time = [tempDic[@"message_time"] integerValue];
                    if ((time - currentTime) > 5*60) {
                        //大于5分钟 -- 显示时间
                        [tempDic setValue:@"Y" forKey:@"showTime"];
                    }else{
                        [tempDic setValue:@"N" forKey:@"showTime"];
                    }
                    [dataArray addObject:tempDic];
                    currentTime = time;
                    
                    NSString *type = LGNSString(tempDic[@"message_type"]);
                    if ([type isEqualToString:@"image"]||[type isEqualToString:@"video"]) {
                        [mediaArray addObject:tempDic];
                    }
                }
                self.dataArray = [NSArray arrayWithArray:dataArray];
                self.mediaArray = [NSArray arrayWithArray:mediaArray];
               
            }else{
                //其他
                self.tableView.cornerRidus = 10;
                self.tableView.backgroundColor = [UIColor whiteColor];
                self.dataArray = infoArray;
            }
            [self.tableView reloadData];
        }
    } error:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
}

-(void)setItemArray:(NSArray *)itemArray{
    _itemArray = itemArray;
    if (itemArray.count == 0) {
        self.addNodeBtn.hidden = NO;
        [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无就诊记录，可点击添加" offset:0];
    }else{
        self.addNodeBtn.hidden = YES;
        [self.emptyView stopBufferAction];
    }
    
    if ([self.nodeid isEqualToString: @"0"]) {
        self.itemIndex = 0;
        self.headView.itemIndex = 0;
    }else{
        for (NSInteger i=0; i<itemArray.count; i++) {
            NSDictionary *tempDic = itemArray[i];
            NSString *nodeid = LGNSString(tempDic[@"node_id"]);
            if ([nodeid isEqualToString:self.nodeid]) {
                self.itemIndex = i;
                self.headView.itemIndex = i;
                break;
            }
        }
    }
}

-(void)setItemIndex:(NSInteger)itemIndex{
    _itemIndex = itemIndex;
    if (itemIndex<self.itemArray.count) {
        NSDictionary *tempDic = self.itemArray[itemIndex];
        self.noteType = LGNSString(tempDic[@"node_type"]);
        self.nodeid = LGNSString(tempDic[@"node_id"]);
        [self requestNodeData:tempDic];
    }
}

-(void)setDataArray:(NSArray *)dataArray{
    _dataArray = dataArray;
    if (dataArray.count == 0) {
        [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无数据" offset:0];
    }else{
        [self.emptyView stopBufferAction];
    }
}

//添加就诊
-(void)addNodeAction{
    [self editNodeWithNodeid:@"0"];
}

//添加、编辑节点
-(void)editNodeWithNodeid:(NSString *)nodeid{
    [RequestUtil withPOST:@"/doctor/patient.Patient/initAddNode" parameters:@{@"node_id":nodeid,@"patient_id":self.patientid} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        if (code == 200) {
            LGPatientDetailAddNodeView *nodeView = [[LGPatientDetailAddNodeView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H) dataDic:returnData];
            nodeView.diseaseCode = self.diseaseCode;
            nodeView.patientid = self.patientid;
            [[NSObject mainWindow] addSubview:nodeView];
            nodeView.saveNodeData = ^(NSDictionary * _Nonnull dataDic) {
                [RequestUtil withPOST:@"/doctor/patient.Patient/saveNode" parameters:dataDic withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
                    if (code == 200) {
                        [TooltipView showMessage:@"保存成功" offset:0];
                        self.nodeid = LGNSString(returnData[@"node_id"]);
                        self.noteType = LGNSString(returnData[@"node_type"]);
                        [self requestData];
                    }else{
                        [TooltipView showMessage:message offset:0];
                    }
                } error:^(NSError *error) {
                    [TooltipView showMessage:@"保存失败，请重试" offset:0];
                }];
            };
        }else{
            [TooltipView showMessage:message offset:0];
        }
    } error:^(NSError *error) {
        [TooltipView showMessage:@"初始化失败，请重试" offset:0];
    }];
}

//查看患者基本信息
-(void)checkPatientInfoAction{
    LGPatientBasicInfoController *controller = [[LGPatientBasicInfoController alloc]init];
    controller.patientid = self.patientid;
    controller.diseaseCode = self.diseaseCode;
    controller.levelid = self.levelid;
    [self.navigationController pushViewController:controller animated:YES];
}

//团队咨询
-(void)consultButtonAction{
    __weak typeof(self) weakSelf = self;
    [LGAlertTool closeAlertWithTitle:@"提示" content:@"将为患者开启一次团队咨询（不消耗服务次数）" sureTitle:@"确认开启" sureAction:^{
        [RequestUtil withPOST:@"/doctor/visit.visit/createTeamAppointment" parameters:@{@"patient_id":weakSelf.patientid,@"level_id":weakSelf.levelid} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
            if(code == 200){
                NSMutableArray *tempArray = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
                for (UIViewController *controller in tempArray) {
                    if([controller isKindOfClass:[TUIGroupChatViewController class]]){
                        [tempArray removeObject:controller];
                        break;
                    }
                }
                self.navigationController.viewControllers = tempArray;
                TUIChatConversationModel *model = [[TUIChatConversationModel alloc]init];
                model.title = LGNSString(returnData[@"patient"][@"realname"]);
                model.groupID = LGNSString(returnData[@"im_group_id"]);
                TUIGroupChatViewController *controller = [[TUIGroupChatViewController alloc]init];
                controller.appointment_id = LGNSString(returnData[@"appointment_id"]);
                controller.doctorid = LGNSString(returnData[@"system_user_id"]);
                controller.roomKey = model.groupID;
                controller.needCustomeData = YES;
                [controller setConversationData:model];
                [weakSelf.navigationController pushViewController:controller animated:YES];
            }else{
                [TooltipView showMessage:message offset:0];
            }
        } error:^(NSError *error) {
            [TooltipView showMessage:@"请求失败，请重试" offset:0];
        }];
    }];
}

//电话随访
-(void)phoneFollowUpAction{
    LGMedicineBallPhoneController *controller = [[LGMedicineBallPhoneController alloc]init];
    controller.patientid = self.patientid;
    controller.planid = @"0";
    controller.levelid = self.levelid;
    [self.navigationController pushViewController:controller animated:YES];
}

//查看报告图片
-(void)checkPhotoDetail{
    LGPatientBreathePhotoController *controller = [[LGPatientBreathePhotoController alloc]init];
    controller.photoArray = self.photoArray;
    [self.navigationController pushViewController:controller animated:YES];
}

//上传报告
-(void)uploadReportAction{
    NSDictionary *tempDic = self.itemArray[self.itemIndex];
    LGUploadIdentReportController *controller = [[LGUploadIdentReportController alloc]init];
    controller.patientid = self.patientid;
    controller.nodeid = LGNSString(tempDic[@"node_id"]);
    [self.navigationController pushViewController:controller animated:YES];
}

//配置量表
-(void)configEvaForm{
    NSDictionary *tempDic = self.itemArray[self.itemIndex];
    if (self.itemIndex<self.itemArray.count) {
        NSDictionary *tempDic = self.itemArray[self.itemIndex];
        LGJoinProjectViewController *controller = [[LGJoinProjectViewController alloc]init];
        controller.diseaseCode = self.diseaseCode;
        controller.patientid = self.patientid;
        controller.nodeType = LGNSString(tempDic[@"node_type"]);
        controller.nodeid = LGNSString(tempDic[@"node_id"]);
        [self.navigationController pushViewController:controller animated:YES];
    }
}

//操作台-展开、收起
-(void)openButtonAction:(UIButton *)sender{
    sender.selected = !sender.selected;
    [sender setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:3];
    CGFloat height = viewPix(62)+bottomSafeBarHeight/2.0;
    if (sender.selected == YES) {
        height = (isPad==YES)?(viewPix(62)+bottomSafeBarHeight/2.0):(viewPix(227)+bottomSafeBarHeight/2.0);
    }
    [UIView animateWithDuration:0.4 animations:^{
        self.bottomView.frame = CGRectMake(0, Screen_H-topBarHeight-height, Screen_W, height);
        self.bottomItemView.alpha = (sender.selected == YES)?1:0;
    }];
}

-(void)bottomItemButtonAction:(UIButton *)sender{
    NSString *title = [sender titleForState:UIControlStateNormal];
    if ([title isEqualToString:@"添加就诊"]) {
        [self editNodeWithNodeid:@"0"];
        
    }else if ([title isEqualToString:@"上传报告"]){
        if (self.itemIndex<self.itemArray.count) {
            NSDictionary *tempDic = self.itemArray[self.itemIndex];
            LGUploadIdentReportController *controller = [[LGUploadIdentReportController alloc]init];
            controller.patientid = self.patientid;
            controller.nodeid = LGNSString(tempDic[@"node_id"]);
            [self.navigationController pushViewController:controller animated:YES];
        }else{
            [TooltipView showMessage:@"请先添加就诊" offset:0];
        }
        
    }else if ([title isEqualToString:@"加入项目"]){
        if (self.itemIndex<self.itemArray.count) {
            NSDictionary *tempDic = self.itemArray[self.itemIndex];
            LGJoinProjectViewController *controller = [[LGJoinProjectViewController alloc]init];
            controller.diseaseCode = self.diseaseCode;
            controller.patientid = self.patientid;
            controller.nodeType = LGNSString(tempDic[@"node_type"]);
            controller.nodeid = LGNSString(tempDic[@"node_id"]);
            [self.navigationController pushViewController:controller animated:YES];
        }else{
            [TooltipView showMessage:@"请先添加就诊" offset:0];
        }
        
    }else if ([title isEqualToString:@"体征监测"]){
        LGCancerMonitoringController *controller = [[LGCancerMonitoringController alloc]init];
        controller.patientid = self.patientid;
        controller.diseaseCode = self.diseaseCode;
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if ([title isEqualToString:@"服药情况"]){
        LGMedicineManageController *controller = [[LGMedicineManageController alloc]init];
        controller.patientid = self.patientid;
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if ([title isEqualToString:@"检验检查报告"]){
        LGReportingCenterController *controller = [[LGReportingCenterController alloc]init];
        controller.patientid = self.patientid;
        controller.diseaseCode = self.diseaseCode;
        controller.currentIndex = 0;
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if ([title isEqualToString:@"呼吸训练记录"]){
        LGBreathRecordController *controller = [[LGBreathRecordController alloc]init];
        controller.patientid = self.patientid;
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if ([title isEqualToString:@"治疗记录"]){
        // 1-手术、 2-放疗、 3-化疗、 4-靶向治疗、 5-免疫治疗、 6-内分泌治疗、 7-中医治疗、 8-介入治疗、 9-其他治疗
        LGCancerTreatRecordController *controller = [[LGCancerTreatRecordController alloc]init];
        controller.patientid = self.patientid;
        controller.levelid = self.levelid;
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if ([title isEqualToString:@"测评记录"]){
        LGEvaluationReportController *controller = [[LGEvaluationReportController alloc]init];
        controller.patientid = self.patientid;
        controller.title = @"测评记录";
        [controller viewWillAppearAction];
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if ([title isEqualToString:@"开具医嘱"]){
        LGAddDoctorAdviceController *controller = [[LGAddDoctorAdviceController alloc]init];
        controller.patientid = self.patientid;
        controller.followid = @"";
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if ([title isEqualToString:@"添加随访总结"]){
        LGMedicineBallFollowUpRecorder *controller = [[LGMedicineBallFollowUpRecorder alloc]init];
        controller.planid = @"0";
        controller.patientid = self.patientid;
        __weak typeof(self) weakSelf = self;
        controller.opinionSaveSuccess = ^(NSDictionary * _Nonnull dataDic) {
            weakSelf.nodeid = LGNSString(dataDic[@"node_id"]);
            weakSelf.noteType = LGNSString(dataDic[@"node_type"]);
            [weakSelf requestData];
        };
        [self.navigationController pushViewController:controller animated:YES];
    }
}

//查看推荐医生详情
-(void)checkDoctorDetail:(NSNotification *)notification{
    NSDictionary *tempDic = notification.userInfo;
    LGPersionalDataController *controller = [[LGPersionalDataController alloc]init];
    controller.userId = LGNSString(tempDic[@"doctorId"]);
    [self.navigationController pushViewController:controller animated:YES];
}

//查看视频咨询订单详情
-(void)checkVideoOrderDetail:(NSNotification *)notification{
    NSDictionary *tempDic = notification.userInfo;
    LGOrderDetailController *controller = [[LGOrderDetailController alloc]init];
    controller.appointId = LGNSString(tempDic[@"appointId"]);
    [self.navigationController pushViewController:controller animated:YES];
}

//服务包详情
-(void)checkServiceDetail:(NSNotification *)notification{
    NSDictionary *tempDic = notification.userInfo;
    LGServiceDetailController *controller = [[LGServiceDetailController alloc]init];
    controller.vipId = LGNSString(tempDic[@"vipId"]);
    [self.navigationController pushViewController:controller animated:YES];
}

//去做量表评估
-(void)checkEvaluationDetail:(NSNotification *)notification{
    NSDictionary *tempDic = notification.userInfo;
    LGGetWebViewController *controller = [[LGGetWebViewController alloc]init];
    controller.urlStr = LGNSString(tempDic[@"urlStr"]);
    [self.navigationController pushViewController:controller animated:YES];
}

//随访及医嘱记录
-(void)checkDoctorAdviceDetail:(NSNotification *)notification{
//    NSDictionary *tempDic = notification.userInfo;
    LGFollowAdviceRecordController *controller = [[LGFollowAdviceRecordController alloc]init];
    controller.patientid = self.patientid;
    [self.navigationController pushViewController:controller animated:YES];
}

//播放语音
- (void)playVoiceMessage:(NSDictionary *)dataDic cell:(LGBubbleMessageCell *)cell{
    LGVoiceMessageCell *voiceCell = (LGVoiceMessageCell *)cell;
    [self.manager playVoiceMessage:dataDic cell:voiceCell];
}

//查看图片大图
- (void)showImageMessage:(NSDictionary *)dataDic cell:(LGBubbleMessageCell *)cell{
    LGImageMessageCell *imageCell = (LGImageMessageCell *)cell;
    CGRect frame = [imageCell.thumb convertRect:imageCell.thumb.bounds toView:[UIApplication sharedApplication].delegate.window];
    LGMessageMediaView *mediaView = [[LGMessageMediaView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, Screen_Height)];
    mediaView.dataArray = self.mediaArray;
    [mediaView setThumb:imageCell.thumb frame:frame];
    [mediaView showMediaView:dataDic];
    [[UIApplication sharedApplication].keyWindow addSubview:mediaView];
}

//播放视频
- (void)showVideoMessage:(NSDictionary *)dataDic cell:(LGBubbleMessageCell *)cell{
    LGVideoMessageCell *videoCell = (LGVideoMessageCell *)cell;
    CGRect frame = [videoCell.thumbView convertRect:videoCell.thumbView.bounds toView:[UIApplication sharedApplication].delegate.window];
    LGMessageMediaView *mediaView = [[LGMessageMediaView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, Screen_Height)];
    mediaView.dataArray = self.mediaArray;
    [mediaView setThumb:videoCell.thumbView frame:frame];
    [mediaView showMediaView:dataDic];
    [[UIApplication sharedApplication].keyWindow addSubview:mediaView];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if ([self.noteType isEqualToString:@"4"]) {
        //咨询
        return 1;
    }else{
        return self.dataArray.count;
    }
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if ([self.noteType isEqualToString:@"4"]) {
        //咨询
        return self.dataArray.count;
    }else{
        //其他
        NSArray *tempArray = self.dataArray[section][@"lists"];
        return tempArray.count;
    }
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //随访记录
    if ([self.noteType isEqualToString:@"4"]) {
        //聊天消息
        NSDictionary *tempDic = self.dataArray[indexPath.row];
        NSString *reuseId = LGNSString(tempDic[@"original_msg_type"]);
        if ([LGNSString(tempDic[@"original_msg_type"]) isEqualToString:@"TIMCustomElem"]) {
            //自定义消息
            NSDictionary *dataDic = [ObjectTool jsonToObject:tempDic[@"content"][@"data"]];
            reuseId = LGNSString(dataDic[@"businessID"]);
            if ([self.systemArray containsObject:reuseId]) {
                LGSystemMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseId forIndexPath:indexPath];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                cell.dataDic = tempDic;
                return cell;
            }else{
                LGBubbleMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseId forIndexPath:indexPath];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                cell.dataDic = tempDic;
                cell.delegate = self;
                return cell;
            }
        }else{
            LGBubbleMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseId forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.dataDic = tempDic;
            cell.delegate = self;
            return cell;
        }
        
    }else{
        NSDictionary *sectionDic = self.dataArray[indexPath.section];
        NSString *type = LGNSString(sectionDic[@"dtype"]);
        NSArray *tempArray = sectionDic[@"lists"];
        if ([type isEqualToString:@"text"]) {
            //文本类型
            LGPatientBreatheTextCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TextCell" forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.contentLabel.text = LGNSString(tempArray[indexPath.row]);
            return cell;
        }else{
            //1-检验 、 2-检查 、 3-量表 、 4-文本 、 5-聊下消息
            NSString *type = LGNSString(tempArray[indexPath.row][@"item_type"]);
            if ([type isEqualToString:@"1"] || [type isEqualToString:@"2"]) {
                //检验检查
                LGPatientBreatheReportCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ReportCell" forIndexPath:indexPath];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                cell.dataDic = tempArray[indexPath.row];
                cell.lineView.hidden = (indexPath.row<tempArray.count-1)?NO:YES;
                return cell;
            }else{
                LGPatientDetailBreatheCell *followCell = [tableView dequeueReusableCellWithIdentifier:@"OtherCell" forIndexPath:indexPath];
                followCell.selectionStyle = UITableViewCellSelectionStyleNone;
                followCell.dataDic = tempArray[indexPath.row];
                followCell.lineView.hidden = (indexPath.row<tempArray.count-1)?NO:YES;
                return followCell;
            }
        }
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (![self.noteType isEqualToString:@"4"]) {
        //非聊天消息
        NSDictionary *sectionDic = self.dataArray[indexPath.section];
        //文本类型 -- 跳转到报告详情
        if ([LGNSString(sectionDic[@"dtype"]) isEqualToString:@"text"]){
            NSString *reportid = LGNSString(sectionDic[@"report_id"]);
            if (![reportid isEmptyString]) {
                //有报告id则跳转
                LGSingleReportDetailController *controller = [[LGSingleReportDetailController alloc]init];
                controller.recordid = reportid;
                [self.navigationController pushViewController:controller animated:YES];
            }
        }else{
            NSDictionary *tempDic = sectionDic[@"lists"][indexPath.row];
            //1-检验 、 2-检查 、 3-量表 、 4-文本 、 5-聊下消息
            NSString *itemType = LGNSString(tempDic[@"item_type"]);
            if ([itemType isEqualToString:@"1"] || [itemType isEqualToString:@"2"]) {
                //检验、检查 --> 有报告则去报告详情，没报告就去上传报告
                NSString *recordid = LGNSString(tempDic[@"id"]);
                if ([recordid integerValue]>0) {
                    LGSingleReportDetailController *controller = [[LGSingleReportDetailController alloc]init];
                    controller.recordid = recordid;
                    [self.navigationController pushViewController:controller animated:YES];
                }else{
                    LGUploadIdentReportController *controller = [[LGUploadIdentReportController alloc]init];
                    controller.patientid = self.patientid;
                    [self.navigationController pushViewController:controller animated:YES];
                }
                
            }else if([itemType isEqualToString:@"3"]){
                //H5
                NSString *url = LGNSString(tempDic[@"url"]);
                if ([url isEmptyString]) {
                    [TooltipView showMessage:@"暂无报告" offset:0];
                }else{
                    LGGetWebViewController *controller = [[LGGetWebViewController alloc]init];
                    controller.urlStr = url;
                    [self.navigationController pushViewController:controller animated:YES];
                }
            }
        }
        
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    CGFloat height = [self.noteType isEqualToString:@"4"]?0.01: viewPix(40);
    return height;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if ([self.noteType isEqualToString:@"4"]) {
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, 0.01)];
        return view;
    }else{
        LGPatientBreatheHeader *headerView = [[LGPatientBreatheHeader alloc]initWithFrame:CGRectMake(0, 0, Screen_W-viewPix(32), viewPix(40))];
        headerView.dataDic = self.dataArray[section];
        [headerView.uploadBtn addTarget:self action:@selector(uploadReportAction) forControlEvents:UIControlEventTouchUpInside];
        [headerView.evaButton addTarget:self action:@selector(configEvaForm) forControlEvents:UIControlEventTouchUpInside];
        return headerView;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    NSArray *tempArray = [self.noteType isEqualToString:@"4"] ? @[] : self.dataArray[section][@"lists"];
    CGFloat height = ([self.noteType isEqualToString:@"4"] || section >= self.dataArray.count-1 || tempArray.count == 0)?0.01: viewPix(12);
    return height;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    NSArray *tempArray = [self.noteType isEqualToString:@"4"] ? @[] : self.dataArray[section][@"lists"];
    CGFloat height = ([self.noteType isEqualToString:@"4"] || section >= self.dataArray.count-1 || tempArray.count == 0)?0.01: viewPix(15);
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W-viewPix(32), height)];
    view.backgroundColor = [UIColor whiteColor];
    view.clipsToBounds = YES;
    
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, viewPix(7), Screen_W-viewPix(32), viewPix(5))];
    lineView.backgroundColor = [UIColor colorWithString:@"#F3F7F8"];
    [view addSubview:lineView];
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([self.noteType isEqualToString:@"4"]) {
        static CGFloat screenWidth = 0;
        if (screenWidth == 0) {
            screenWidth = Screen_Width;
        }
        return [self getCellDataHeightAtIndex:indexPath.row Width:screenWidth];
    }else{
        return UITableViewAutomaticDimension;
    }
}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60.f;
}

- (CGFloat)getCellDataHeightAtIndex:(NSUInteger)index Width:(CGFloat)width {
    CGFloat height = 0;
    CGFloat timeHeight = 0;
    @autoreleasepool {
        if (index < self.dataArray.count) {
            NSDictionary *tempDic = self.dataArray[index];
            //是否显示时间
            timeHeight = [LGNSString(tempDic[@"showTime"]) isEqualToString:@"Y"]?20:0;
            //消息类型
            NSString *key = LGNSString(tempDic[@"message_id"]);
            if ([self.heightDic.allKeys containsObject:key]) {
                height = [[self.heightDic objectForKey:key] floatValue];
            }
            if (height == 0) {
                NSString *msgType = LGNSString(tempDic[@"original_msg_type"]);
                if ([msgType isEqualToString:@"TIMCustomElem"]) {
                    //自定义消息
                    NSDictionary *dataDic = [ObjectTool jsonToObject:tempDic[@"content"][@"ext"]];
                    NSDictionary *customDic = [ObjectTool jsonToObject:tempDic[@"content"][@"data"]];
                    NSString *reuseId = LGNSString(customDic[@"businessID"]);
                    height = [LGCustomCellData caculateCellHeight:dataDic];
                    if (![self.systemArray containsObject:reuseId]) {
                        height += viewPix(40);
                    }

                }else if ([msgType isEqualToString:@"TIMTextElem"]){
                    height = [self heightWithType:@"TIMTextElem" dataDic:tempDic];
                    
                }else if ([msgType isEqualToString:@"TIMSoundElem"]){
                    height = [self heightWithType:@"TIMSoundElem" dataDic:tempDic];
                    
                }else if ([msgType isEqualToString:@"TIMImageElem"]){
                    height = [self heightWithType:@"TIMImageElem" dataDic:tempDic];
                    
                }else if ([msgType isEqualToString:@"TIMVideoFileElem"]){
                    height = [self heightWithType:@"TIMVideoFileElem" dataDic:tempDic];
                }
                [self.heightDic setObject:@(height) forKey:key];
            }
        }
    }
    return height+timeHeight;
}


-(CGFloat)heightWithType:(NSString *)msgType dataDic:(NSDictionary *)dataDic{
    NSString *sender = LGNSString(dataDic[@"sender"]);
    TMsgDirection direction = [sender isEqualToString:@"member"]?MsgDirectionIncoming:MsgDirectionOutgoing;
    CGFloat height = 0;
    if ([msgType isEqualToString:@"TIMTextElem"]){
        //文字
        TUITextMessageCellData *textData = [[TUITextMessageCellData alloc]initWithDirection:direction];
        textData.content = LGNSString(dataDic[@"content"][@"text"]);
        height = 60 + [textData contentSize].height;
        
    }else if ([msgType isEqualToString:@"TIMSoundElem"]){
        //语音
        TUIVoiceMessageCellData *voiceData = [[TUIVoiceMessageCellData alloc]initWithDirection:direction];
        voiceData.duration = [dataDic[@"content"][@"second"] intValue];
        voiceData.length = [dataDic[@"content"][@"size"] intValue];
        height = 60 + [voiceData contentSize].height;
        
    }else if ([msgType isEqualToString:@"TIMImageElem"]){
        //图片
        NSDictionary *thumDic = [dataDic[@"content"] lastObject];
        CGFloat thumHeight = [thumDic[@"height"] floatValue];
        CGFloat thumWidth = [thumDic[@"width"] floatValue];
        if(thumHeight > thumWidth){
            thumWidth = thumWidth / thumHeight * TImageMessageCell_Image_Height_Max;
            thumHeight = TImageMessageCell_Image_Height_Max;
        } else {
            thumHeight = thumHeight / thumWidth * TImageMessageCell_Image_Width_Max;
            thumWidth = TImageMessageCell_Image_Width_Max;
        }
        height = 60 + thumHeight;
        
    }else if ([msgType isEqualToString:@"TIMVideoFileElem"]){
        //视频
        CGFloat thumHeight = [dataDic[@"content"][@"thumb_height"] floatValue];
        CGFloat thumWidth = [dataDic[@"content"][@"thumb_width"] floatValue];
        if(thumHeight > thumWidth){
            thumWidth = thumWidth / thumHeight * TVideoMessageCell_Image_Height_Max;
            thumHeight = TVideoMessageCell_Image_Height_Max;
        } else {
            thumHeight = thumHeight / thumWidth * TVideoMessageCell_Image_Width_Max;
            thumWidth = TVideoMessageCell_Image_Width_Max;
        }
        height = 60 + thumHeight;
    }
    if (height < 55) height = 55;
    return height;
}


#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.title = @"患者档案";
    [self.view addSubview:self.headView];
    [self.view addSubview:self.tableView];
    [self.view addSubview:self.bottomView];
    [self createBottomView];
    [self emptyViewWithSuperView:self.view frame:CGRectMake(viewPix(16), 0, Screen_W-viewPix(32), Screen_H-topBarHeight)];
    [self.emptyView addSubview:self.addNodeBtn];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headView.mas_bottom).offset(-viewPix(5));
        make.left.equalTo(self.view).offset(viewPix(16));
        make.width.equalTo(@(Screen_W-viewPix(32)));
        make.bottom.equalTo(self.bottomView.mas_top).offset(-viewPix(5));
    }];
    [self.emptyView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.tableView).offset(0);
        make.height.equalTo(self.tableView);
    }];
    [self.addNodeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.emptyView.mas_centerY).offset(viewPix(40));
        make.centerX.equalTo(self.emptyView);
        make.width.equalTo(@(viewPix(186)));
        make.height.equalTo(@(viewPix(62)));
    }];
}

-(UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(viewPix(16), 0, Screen_W-viewPix(32), Screen_H-topBarHeight) style:UITableViewStyleGrouped];
        [_tableView registerClass:[LGPatientDetailBreatheCell class] forCellReuseIdentifier:@"OtherCell"];
        [_tableView registerClass:[LGPatientBreatheTextCell class] forCellReuseIdentifier:@"TextCell"];
        [_tableView registerClass:[LGPatientBreatheReportCell class] forCellReuseIdentifier:@"ReportCell"];
        [self.tableView registerClass:[LGTextMessageCell class] forCellReuseIdentifier:@"TIMTextElem"];
        [self.tableView registerClass:[LGVoiceMessageCell class] forCellReuseIdentifier:@"TIMSoundElem"];
        [self.tableView registerClass:[LGImageMessageCell class] forCellReuseIdentifier:@"TIMImageElem"];
        [self.tableView registerClass:[LGVideoMessageCell class] forCellReuseIdentifier:@"TIMVideoFileElem"];
        [self.tableView registerClass:[LGPatientCardRecordCell class] forCellReuseIdentifier:@"TIMCustom_02"];
        [self.tableView registerClass:[LGRecommendDoctorCell2 class] forCellReuseIdentifier:@"TIMCustom_08"];
        [self.tableView registerClass:[LGRecommendServiceCell2 class] forCellReuseIdentifier:@"TIMCustom_09"];
        [self.tableView registerClass:[LGConsultEvaluationCell2 class] forCellReuseIdentifier:@"TIMCustom_10"];
        [self.tableView registerClass:[LGFollowUpRecommedCell2 class] forCellReuseIdentifier:@"TIMCustom_17"];
        [self.tableView registerClass:[LGConsultationAdviceCell2 class] forCellReuseIdentifier:@"TIMCustom_20"];
        [_tableView setShadoWithColor:@"#B0B2B2" offset:CGSizeMake(0, 2) opacity:0.25 radius:10];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.cornerRidus = 10;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W-viewPix(32), viewPix(10))];
    }
    return _tableView;
}

-(UIView *)tableHeaderView{
    if(!_tableHeaderView){
        _tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W-viewPix(32), viewPix(40))];
        
        UIButton *checkButton = [UIButton buttonWithTitle:@"查看" titleFont:LGFont(12) textColor:@"#999999" imageName:@"grayTip16"];
        checkButton.frame = CGRectMake(viewPix(12), viewPix(8), Screen_W-viewPix(56), viewPix(32));
        checkButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        checkButton.backgroundColor = [UIColor colorWithString:@"#FEF7EE"];
        checkButton.cornerRidus = 2;
        [checkButton addTarget:self action:@selector(checkPhotoDetail) forControlEvents:UIControlEventTouchUpInside];
        [checkButton setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:0];
        [_tableHeaderView addSubview:checkButton];
        
        UIImageView *iconView = [[UIImageView alloc]initWithFrame:CGRectMake(viewPix(10), viewPix(10), viewPix(12), viewPix(12))];
        iconView.image = [UIImage imageNamed:@"电话随访-惊叹号"];
        [checkButton addSubview:iconView];
        [checkButton addSubview:self.warnLabel];
    }
    return _tableHeaderView;
}

-(UILabel *)warnLabel{
    if(!_warnLabel){
        _warnLabel = [UILabel lableWithText:@"提醒：" colorString:@"#606266" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
        _warnLabel.frame = CGRectMake(viewPix(26), 0, Screen_W-viewPix(56)-viewPix(80), viewPix(32));
    }
    return _warnLabel;
}


-(LGPatientDetailHeaderView *)headView{
    if(!_headView){
        _headView = [[LGPatientDetailHeaderView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(221))];
        [_headView.consultBtn addTarget:self action:@selector(consultButtonAction) forControlEvents:UIControlEventTouchUpInside];
        [_headView.phoneBtn addTarget:self action:@selector(phoneFollowUpAction) forControlEvents:UIControlEventTouchUpInside];
        [_headView.historyBtn addTarget:self action:@selector(checkPatientInfoAction) forControlEvents:UIControlEventTouchUpInside];
        [_headView.baseView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(checkPatientInfoAction)]];
    }
    return _headView;
}

-(UIButton *)addNodeBtn{
    if(!_addNodeBtn){
        _addNodeBtn = [UIButton buttonWithImage:@"患者档案-添加就诊" frame:CGRectMake(0, 0, viewPix(186), viewPix(62))];
        _addNodeBtn.hidden = YES;
        [_addNodeBtn addTarget:self action:@selector(addNodeAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _addNodeBtn;
}

-(UIView *)bottomView{
    if(!_bottomView){
        _bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, Screen_H-topBarHeight-viewPix(62)-bottomSafeBarHeight/2.0, Screen_W, viewPix(62)+bottomSafeBarHeight/2.0)];
        _bottomView.backgroundColor = [UIColor whiteColor];
    }
    return _bottomView;
}

-(UIView *)bottomItemView{
    if(!_bottomItemView){
        CGFloat height = (isPad==YES)?viewPix(88):viewPix(165);
        _bottomItemView = [[UIView alloc]initWithFrame:CGRectMake(0, viewPix(62), Screen_W, height)];
        _bottomItemView.backgroundColor = [UIColor whiteColor];
        _bottomItemView.clipsToBounds = YES;
        _bottomItemView.alpha = 0;
    }
    return _bottomItemView;
}

-(UIButton *)openButton{
    if(!_openButton){
        _openButton = [UIButton buttonWithTitle:@"展开" titleFont:LGFont(14) textColor:@"#666666" imageName:@"grayTipDown"];
        _openButton.frame = CGRectMake(Screen_W-viewPix(60), viewPix(7), viewPix(50), viewPix(45));
        [_openButton setSelectTitle:@"收起" selectImage:@"grayTipUp"];
        [_openButton setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:3];
        [_openButton addTarget:self action:@selector(openButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _openButton;
}

-(void)createBottomView{
    UILabel *titleLabel = [UILabel lableWithText:@"操作台" colorString:@"#282828" textFont:LGFontWeight(18, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    titleLabel.frame = CGRectMake(viewPix(12), viewPix(12), 60, viewPix(25));
//    [self.bottomView addSubview:titleLabel];
    [self.bottomView addSubview:self.openButton];
    [self.bottomView addSubview:self.bottomItemView];
    
    CGFloat buttonW = (Screen_W-viewPix(34)-viewPix(65))/2.0;
    NSArray *titleArray1 = @[@"添加就诊",@"添加随访总结"];
    for (NSInteger i=0; i<titleArray1.count; i++) {
        UIButton *itemBtn = [UIButton buttonWithTitle:titleArray1[i] titleFont:LGFontWeight(16, UIFontWeightMedium) textColor:kThemeColor frame:CGRectMake(viewPix(12)+(buttonW+viewPix(10))*(i%2), viewPix(7), buttonW, viewPix(45))];
        [itemBtn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"患者详情-%@",titleArray1[i]]] forState:UIControlStateNormal];
        [itemBtn addBorder:kThemeColor lineWidth:1 cornerRidus:10];
        itemBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
        itemBtn.tag = 1000+i;
        [itemBtn addTarget:self action:@selector(bottomItemButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.bottomView addSubview:itemBtn];
    }
    
    CGFloat itemW = (isPad==YES)?(Screen_W-viewPix(56))/5.0:(Screen_W-viewPix(40))/3.0;
    NSInteger count = (isPad==YES)?5:3;
    NSArray *titleArray = @[@"体征监测",@"服药情况",@"检验检查报告",@"呼吸训练记录",@"治疗记录",@"测评记录",@"开具医嘱"];
    for (NSInteger i=0; i<titleArray.count; i++) {
        UIButton *itemBtn = [UIButton buttonWithTitle:titleArray[i] titleFont:LGFontWeight(16, UIFontWeightMedium) textColor:kThemeColor frame:CGRectMake(viewPix(12)+(itemW+viewPix(8))*(i%count), viewPix(55)*(i/count), itemW, viewPix(45))];
        [itemBtn addBorder:kThemeColor lineWidth:1 cornerRidus:10];
        [itemBtn addTarget:self action:@selector(bottomItemButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.bottomItemView addSubview:itemBtn];
    }
}

@end
